//
//  HNSH_InviteFriendsCellInfoView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/31.
//

#import "HNSH_InviteFriendsCellInfoView.h"

@interface HNSH_InviteFriendsCellInfoView ()

/**  */
@property (nonatomic, strong)UIImageView * headImgView;
/**  */
@property (nonatomic, strong)UILabel * nameLabel;
/**  */
@property (nonatomic, strong)UILabel * inviteLabel;
/**  */
@property (nonatomic, strong)UIImageView * qrImgView;

@end

@implementation HNSH_InviteFriendsCellInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = RGBA(255, 255, 255, 0.6);
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_InviteFriendsModel *)model {
    _model = model;
    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
    self.nameLabel.text = model.nickname;
    self.inviteLabel.text = [NSString stringWithFormat:@"邀请码：%@",model.invite_code];
    self.qrImgView.image = [UIImage createNonInterpolatedUIImageFormCIImage:[UIImage creatQRcodeWithUrlstring:model.invite_url] withSize:244];
}

- (void)configUI {
    
    [self addSubview:self.headImgView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.inviteLabel];
    [self addSubview:self.qrImgView];
    
    [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(15);
        make.width.height.mas_equalTo(48);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headImgView);
        make.left.mas_equalTo(self.headImgView.mas_right).offset(12);
        make.height.mas_equalTo(25);
    }];
    [self.inviteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.headImgView);
        make.left.mas_equalTo(self.headImgView.mas_right).offset(12);
        make.height.mas_equalTo(17);
    }];
    [self.qrImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-15);
        make.width.height.mas_equalTo(60);
    }];
    
}

//MARK: Getter Methods
- (UIImageView *)headImgView{
    if (!_headImgView) {
        _headImgView = [UIImageView new];
        _headImgView.image = [UIImage imageNamed:@"mine_user"];
    }
    return _headImgView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.text = @"XXX";
    }
    return _nameLabel;
}

- (UILabel *)inviteLabel{
    if (!_inviteLabel) {
        _inviteLabel = [UILabel new];
        _inviteLabel.font = [UIFont systemFontOfSize:12];
        _inviteLabel.textColor = [UIColor appGrayLabelColor];
        _inviteLabel.text = @"XXX";
    }
    return _inviteLabel;
}

- (UIImageView *)qrImgView{
    if (!_qrImgView) {
        _qrImgView = [UIImageView new];
    }
    return _qrImgView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
